/**
 * 
 */
function checkDefaultOptions() {
	for ( var i = 0; i < services.length; i++) {
		if (!localStorage[services[i].id + "_ENABLED"]) {
			localStorage[services[i].id + "_ENABLED"] = "true";
		}
	}
}

function isEnabled(id) {
	return (localStorage[id + "_ENABLED"] == "true");
}

function setEnabled(id, value) {
	if (value) {
		localStorage[id + "_ENABLED"] = "true";
	} else {
		localStorage[id + "_ENABLED"] = "false";
	}
}

// Only to called from options.html
function loadOptions() {
	var divElement = document.getElementById("optionPanel");
	var saveButton = divElement.getElementsByTagName("button")[0];
	for ( var i = 0; i < services.length; i++) {
		var newInput = document.createElement("input");
		newInput.type = "checkbox";
		newInput.value = services[i].id;
		newInput.checked = isEnabled(services[i].id);
		newInput.innerHTML = services[i].name;
		divElement.insertBefore(newInput, saveButton);
		divElement.insertBefore(document.createElement("br"), saveButton);
	}
}

function saveOptions() {
	var divElement = document.getElementById("optionPanel");
	var inputs = divElement.getElementsByTagName("input");
	for ( var i = 0; i < inputs.length; i++) {
		setEnabled(inputs[i].value, inputs[i].checked);
	}
}
